package com.crm.jdy.service.client;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.crm.jdy.common.mapper.ActivitiBasunessMapper;
import com.crm.jdy.common.pojo.BasunessMessage;
import com.crm.jdy.common.mapper.BasunessMessageMapper;
import org.apache.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**   
 * @Description:(工作流对应的审批信息服务实现)
 *
 * @version: V1.0
 * @author: kong
 * 
 */
@Service(version = "${service.version}")
@Component
public class BasunessMessageServiceImpl  extends ServiceImpl<BasunessMessageMapper,BasunessMessage> implements BasunessMessageService  {


    @Autowired
    BasunessMessageMapper basunessMessageMapper;

    @Autowired
    ActivitiBasunessMapper activitiBasunessMapper;

    @Override
    public List<BasunessMessage> seleteBasunessMessage(BasunessMessage basunessMessage) {
//        QueryWrapper<BasunessMessage> queryWrapper = new QueryWrapper<>();
//        if( basunessMessage.getBid() !=null &&  !basunessMessage.getBid().isEmpty()  ){
//            queryWrapper.eq("bid",basunessMessage.getBid());
//        }
//        if( basunessMessage.getKey() !=null && !basunessMessage.getKey().isEmpty() ){
//            queryWrapper.like("key",basunessMessage.getKey());
//        }
//        if( basunessMessage.getValue() !=null && !basunessMessage.getValue().isEmpty() ){
//            queryWrapper.like("value",basunessMessage.getValue());
//        }
////        if( basunessMessage.getOrders() !=null && basunessMessage.getOrders() > 0 ){
////            queryWrapper.like("orders",basunessMessage.getOrders());
////        }
//        if( basunessMessage.getParentId() !=null && !basunessMessage.getParentId().isEmpty() ){
//            queryWrapper.like("parent_id",basunessMessage.getParentId());
//        }
        return basunessMessageMapper.seleteBasunessMessage(basunessMessage);
    }

    @Override
    public boolean updateBasunessMessage(BasunessMessage basunessMessage) {
        return basunessMessageMapper.updateById(basunessMessage) > 0;
    }

    @Override
    public boolean addBasunessMessage(BasunessMessage basunessMessage) {
        return basunessMessageMapper.insert(basunessMessage) > 0;
    }

    @Override
    public boolean removeBasunessMessage(BasunessMessage basunessMessage) {
        QueryWrapper<BasunessMessage> queryWrapper = new QueryWrapper<>();
        if( basunessMessage.getBid() !=null && !basunessMessage.getBid().isEmpty()){
            queryWrapper.eq("bid",basunessMessage.getBid());
            return basunessMessageMapper.delete(queryWrapper) > 0;
        }
        if( basunessMessage.getParentId() !=null && !basunessMessage.getParentId().isEmpty()){
            queryWrapper.eq("parent_id",basunessMessage.getParentId());
            return basunessMessageMapper.delete(queryWrapper) > 0;
        }
        return false;
    }

    @Override
    public boolean addAllActivitiBasuness(List<BasunessMessage> basuness) {
//        todo  修改流程定义转成部署
//        activitiBasunessMapper.updateById();
        return this.saveBatch(basuness);
    }


}